package com.leyou.item.controller;

import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * 根据传入的分类的pid查询对应的分类的信息
     * 由于一个分类的pid可能对应多个分类，所以返回结果是集合
     * @param pid
     * @return
     */
    @GetMapping("list")
    public List<Category> queryByParentId(@RequestParam("pid")Long pid) {

        List<Category> categories = this.categoryService.queryByParentId(pid);
        if (categories != null) {
            return categories;
        }
        return null;
    }
}
